/********************************************************************
  A SymbolBrowser plugin for JuffEd editor.

  Copyright: 2010 Aleksander Sokoloff <asokol@mail.ru>


  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License.
  version 2 as published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*********************************************************************/


#ifndef DOCUMENT_PARSER_H
#define DOCUMENT_PARSER_H

#include "languages.h"
#include <QObject>
#include <QHash>
#include "items.h"

class SymbolBrowserView;
class ParserThread;
class QTimerEvent;
class QStandardItem;

class Symbol;


class DocumentParser : public QObject
{
  Q_OBJECT

public:
    explicit DocumentParser(SymbolBrowserView *view, QObject * parent = 0);
    virtual ~DocumentParser();

    SymbolBrowserView * view() const { return mView; }

    virtual Language language() const = 0;
    virtual void getText(QString &text) const = 0;
    virtual void skipToLine(int line) = 0;

    bool isActive() const;

    void saveState();

    Item::SortOrder sorted() const { return mSortedBy; }

    bool detailed() const { return mDetailed; }

public slots:
    void refresh();
    void activate();
    void sort(Item::SortOrder order);
    void setDetailed(bool value);

protected:
    void timerEvent(QTimerEvent *event);
    void doRefresh();
    void saveItemStates(QStandardItem *parentItem);

protected slots:
    void onParserFinished();

private:
    SymbolBrowserView * mView;
    ParserThread  *lastParser;
    int delayTimerId;

    QHash<QString, bool> mItemStatesByPath;
    QHash<int, bool> mItemStatesByLine;
    Item::SortOrder mSortedBy;
    bool mDetailed;

    void rebuildChildren(Symbol *parentSymbol, QStandardItem *parentItem, const QString &path);
};



#endif // DOCUMENT_PARSER_H



